package com.atguigu.gulimall.search.thread;


import java.util.concurrent.*;

public class ThreadTest {
    //创建线程池
   public static ExecutorService service = Executors.newFixedThreadPool(10);
    public static void main(String[] args) throws ExecutionException, InterruptedException {
        System.out.println("开始");
/*
     1 继承Thread 类
      Thread01 thread01=new Thread01();
      thread01.start();

*/
/*
       2   实现runnable接口
       Thread02 run = new Thread02();
        new  Thread(run).start();
*/

/*
      3 //实现callable接口
       FutureTask<Integer> futureTask = new FutureTask<>(new Callable01());
        new Thread(futureTask).start();
        //get 等待整个线程执行完成，获取返回结果
        Integer integer = futureTask.get();
        System.out.println(integer);
        System.out.println("结束"+integer);
*/
/*
     //4、线程池
        给线程池直接提交任务
         service.execute(new Thread02());
        创建方法：1、Executors
                 2、

    区别：1、2不能得到返回值，3可以
     1、2、2都不能控制资源
     4、可以控制资源、性能稳定
*/


            /**
             *  七大参数：
             *  corePoolSize：核心线程数
             *  maximumPoolSize:最大线程数
             *  keepAliveTime:存活时间
             *  unit:时间单位
             *  workQueue:阻塞队列
             *  threadFactory：线程创建的工厂
             *  handler：拒绝策略
             *  工作顺序
             */
        ThreadPoolExecutor threadPoolExecutor = new ThreadPoolExecutor(5,
                200,
                10,
                null,
                null,
                null,
                null);
        System.out.println("结束");


    }
    public static class  Thread01 extends Thread{
        @Override
        public void run() {
            System.out.println("当前线程10："+Thread.currentThread().getId());
            int i=1;

            System.out.println("结果："+i);
        }

        }
    public static class  Thread02 implements Runnable {
        @Override
        public void run() {
            System.out.println("当前线程11：" + Thread.currentThread().getId());
            int i = 1;

            System.out.println("结果：" + i);
        }
    }
  public  static  class  Callable01 implements Callable<Integer>{
      @Override
      public Integer call() throws Exception {
          System.out.println("当前线程12：" + Thread.currentThread().getId());
          int i = 1;
          System.out.println("结果：" + i);
          return i++;
      }
  }


}
